import data from '@/common/data.js'; //筛选菜单数据
import validator from '@/common/validator';
import $http from '@/config/requestConfig';
export default {
	data() {
		return {
			// 存取人员类型
			typeList:null,
			// 当前搜索类型
			typeFlag: 0,
			// 记录访问地址
			currentUrl: null,
			listTabs: [{
				name: '找注册人员',
			}, {
				name: '找公司股东',
			}],
			placeData: null,
			loadShow1: false,
			status: 'loadmore',
			// 人员信息
			personMsg: [],
			// 记录总条数
			allSize: null,
			defaultSelected: [],
			filterData: [],
			keyword: '',
			// 记录页数
			page: 1,
			pageSize: 10,
			// 公司的数量
			allCompany: null,
			chooseObj: {},
			// 判断字符a是否存在
			wordA:null,
			// 判断字符b是否存在
			wordB:null
		}
	},
	onReachBottom() {

		// this.refreshArr()
	},
	onLoad: function() {
		// 查询数据
		this.getfindPersonType()
		this.checkPerson()
		
		this.filterData = []
		

		
	},
	methods: {
		// 跳转至企业详情
		toEnterprise(item){
			uni.navigateTo({
				url:`/pagesFind/detailenterprise/detailenterprise?companyCid=${item.companyCid}`
			})
		},
		
		// 查询人员注册分类
		getfindPersonType(){
			let url=this.$baseApp.api.check.findPersonType
			let data1=[]
			$http.get(url).then(res => {
				
				res.data.forEach((item1, index1) => {
					data1.push({
						"name": item1.name,
						"value": item1
					})
				})
				this.typeList=data1
				
					this.filterData.push({
						"name": '类型',
						"type": 'filter',
						"submenu": [{
							"name": "类型",
							"submenu": this.typeList
						}]
					})
					// this.changeSelected()
			});
			
		},
		
		getPlaceData() {
			let data = uni.getStorageSync('filterPlaceData')
			this.placeData = data
			this.areaList = []
			let obj = {
				name: '省份',
				value: '省份',
				submenu: [{
					name: "全部",
					value: "全部"
				}]
			}

			data.forEach(item => {
				obj.submenu.push({
					name: item.name,
					value: 'A' + item.name
				})
			})
			this.placeData.unshift(obj)
			this.areaList.push(obj)
			
		},
		// 切换搜索资源
		clickTabs(item) {
			
			this.typeFlag = item.index

			this.personMsg = []

			
			this.checkPerson()
		},
		// 函数更新
		refreshArr() {
			// console.log("-----------", this.page, this.allPage)
			if (this.page >= this.allPage) {
				this.status = 'nomore';
				return
			}
			this.status = 'loading';
			this.page = ++this.page;
			setTimeout(() => {
				this.checkPerson()
				if (this.page >= this.allPage) this.status = 'nomore';
				else this.status = 'loading';
			}, 2000)
		},
		// 查询注册人员数据
		checkPerson() {
			// 判断当前的资源访问类型
			if (this.typeFlag == 0) {
				this.currentUrl = this.$baseApp.api.dicData.companyRegisteredPersonnelDetailsList
			} else {
				this.currentUrl = this.$baseApp.api.dicData.companyMainStuffList
			}
			let param = {
				'page': this.page,
				'companyName': this.keyword
			}
			if (this.chooseObj.qualification) {
				param.qualification = this.chooseObj.qualification
			}
			if (this.chooseObj.companyProvince) {
				param.companyProvince = this.chooseObj.companyProvince
			}
			if (this.chooseObj.companyCity) {
				param.companyCity = this.chooseObj.companyCity
			}
			this.status = 'loading'
			this.loadShow1 = true
			this.$app.request({
				url: this.currentUrl,
				data: param,
				method: 'GET',
				dataType: 'json',
				success: res => {
					if (res.code == 200) {
						this.allPage = res.data.totalPages
						this.allSize = res.data.totalElements
						if (this.allPage <= 1||res.data.content.length<10) {
							this.status = 'nomore'
						}else{
							this.status = 'loadmore'
						}
						if (this.typeFlag == 0) {
							res.data.content.forEach((item) => {
								if (item.companyRegInfo) {
									
									 item.companyRegInfo.forEach(item2=>{
										 item2.companyRegisterType=validator.joinStr(item2.companyRegisterType,this.keyword)
										 item2.companyRegisterCompany=validator.joinStr(item2.companyRegisterCompany,this.keyword)
										 
									 })
									 item.tagList = item.companyRegInfo
									 	 
								}
								item.name = item.companyHumanName.slice(0, 1)
								item.companyHumanName=validator.joinStr(item.companyHumanName,this.keyword)
								
								this.personMsg.push(item)
							})
						} else {
							res.data.content.forEach((item) => {
								item.companyStuffName=validator.joinStr(item.companyStuffName,this.keyword)
								
								this.personMsg.push(item)
							})
						}

						

					}

				},
				complete: res => {
					this.loadShow1 = false
					uni.stopPullDownRefresh();

				}
			});
		},
		// 搜索
		searchResult(value) {
			
			// 点击搜索  验证不为空后，调用接口
			if (!validator.checkNullValue(this.keyword)) {
				return;
			}
			// 将已有数组清零
			this.page=1
			this.personMsg = []
			this.checkPerson()
		},

		//接收菜单结果
		confirm(e) {
			this.indexArr = e.index;
			this.valueArr = e.value;
			// console.log("this.valueArr", this.valueArr)
			// console.log("this.valueArr", this.valueArr)
			this.chooseObj = {}

			
			this.valueArr[0][0].forEach(item => {
				if (this.chooseObj.qualification) {
					this.chooseObj.qualification += ',' + item.name
				} else {
					this.chooseObj.qualification = item.name
				}
			})

			// console.log("this.chooseObj", this.chooseObj)

			// 将已有数组清零
			this.personMsg = []
			this.checkPerson()
		},
		//修改选中项-示例
		changeSelected() {
			//设置选中项
			// 一下的注释是针对测试数据说明结构的意思，具体传入什么数据，要看你自己数据。如果data.js数据有修改，注意defaultSelected也要修改
			//传入defaultSelected的结构不能错，错了就报错运行异常。 不想选中的请传入null

			this.defaultSelected = [];
			this.$nextTick(() => {
				this.defaultSelected = [
					// [0, 0], //第0个菜单选中 一级菜单的第6项，二级菜单的第0项，三级菜单的第1项

					[
						[0],
						[1],
						[1]
					] //单选菜单选中 第一个筛选的第0项，第二个筛选的第1项，第三个筛选的第1项
				];
			})
		},
	}
}
